//package com.elink.enginerring.controller;
//
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//
//import java.util.Map;
//
//import javax.validation.Valid;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.ModelAttribute;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RequestMethod;
//import org.springframework.web.bind.annotation.RequestParam;
//import org.springframework.web.bind.annotation.RestController;
//
//import com.elink.enginerring.co.BaseCo;
//import com.elink.enginerring.co.CommentCo;
//import com.elink.enginerring.common.Constant;
//import com.elink.enginerring.common.ErrorType;
//import com.elink.enginerring.domain.Praise;
//import com.elink.enginerring.service.CommentService;
//import com.elink.enginerring.util.JSONUtil;
//import com.elink.enginerring.util.LocalUtil;
//
///**
// * 评论接口
// * 
// * @author hxjxiaojun
// * @time 2016年8月30日
// */
//@RestController
//@RequestMapping("/api/comment")
//@Api(value = "论文图书馆评论接口")
//public class CommentController {
//	@Autowired
//	private CommentService commentService;
//
//	/**
//	 * 获取资料的一级评论
//	 * @param co
//	 * @return
//	 */
//	@RequestMapping(value = "/getTopCommentsById", method = RequestMethod.GET)
//	@ApiOperation(value = "分页获取资料的一级评论")
//	public Map<String, Object> getTopCommentsById(@ModelAttribute @Valid CommentCo co) {
//		return commentService.getTopCommentsById(co);
//	}
//	
//	/**
//	 * 获取一级评论下的所有评论
//	 * @param bc
//	 * @return
//	 */
//	@RequestMapping(value = "/getAllCommentsByTopId", method = RequestMethod.GET)
//	@ApiOperation(value = "分页获取一级评论下的评论")
//	public Map<String, Object> getAllCommentsByTopId(@ModelAttribute @Valid BaseCo bc,
//			@ApiParam(value="一级评论的id",required=true) @RequestParam("topId")int topId) {
//		return commentService.getAllCommentsByTopId(bc,topId);
//	}
//	
//	/**
//	 * 添加评论
//	 * @param id
//	 * @param userId
//	 * @param content
//	 * @return
//	 */
//	@RequestMapping(value = "/add", method = RequestMethod.POST)
//	@ApiOperation(value = "发表评论")
//	public Map<String, Object> add(
//			@ApiParam(value = "论文id", required = true) @RequestParam("id") String id,
//			@ApiParam(value = "评论内容", required = true) @RequestParam("content") String content			
//			) {
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) LocalUtil.get();
//		if(userInfo != null && userInfo.containsKey("userId")){
//			if((int)userInfo.get("userType")==Constant.personUserType){//只有个人用户才能够评论
//				String userId =  userInfo.get("userId").toString();
//				return commentService.add(id, userId, content);
//			}else{
//				return JSONUtil.getJSON(ErrorType.AUTHORITY_ERROR);
//			}
//		}
//		return JSONUtil.getJSON(ErrorType.AUTHORITY_ERROR); 
//	}
//	
//	/**
//	 * 回复评论
//	 * @param id
//	 * @param commentId
//	 * @param userId
//	 * @param content
//	 * @return
//	 */
//	@RequestMapping(value = "/addReply", method = RequestMethod.POST)
//	@ApiOperation(value = "回复评论")
//	public Map<String, Object> addReply(
//			@ApiParam(value = "文件资料id", required = true) @RequestParam("id") String id,
//			@ApiParam(value = "评论id", required = true) @RequestParam("commentId") int commentId,
//			@ApiParam(value = "评论内容", required = true) @RequestParam("content") String content) {
//	
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) LocalUtil.get();
//		if(userInfo != null && userInfo.containsKey("userId")){
//			if((int)userInfo.get("userType")==Constant.personUserType){//只有个人用户才能够回复
//				String userId =  userInfo.get("userId").toString();
//				return commentService.addReply(id, commentId, userId, content);
//			}else{
//				return JSONUtil.getJSON(ErrorType.AUTHORITY_ERROR);
//			}
//		}
//		return JSONUtil.getJSON(ErrorType.AUTHORITY_ERROR); 
//	}
//
//	/**
//	 * 评论点赞(顶/踩)
//	 * @param praise
//	 * @return
//	 */
//	@RequestMapping(value = "addPraise", method = RequestMethod.POST)
//	@ApiOperation(value = "评论点赞(顶/踩)")
//	public Map<String, Object> addPraise(@ModelAttribute @Valid Praise praise) {
//
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) LocalUtil.get();
//		if(userInfo != null && userInfo.containsKey("userId")){
//			if((int)userInfo.get("userType")==Constant.personUserType){//只有个人用户才能够点赞
//				String userId =  userInfo.get("userId").toString();
//				praise.setUserId(userId);
//				return commentService.addPraise(praise);
//			}else{
//				return JSONUtil.getJSON(ErrorType.AUTHORITY_ERROR);
//			}
//		}
//		return JSONUtil.getJSON(ErrorType.AUTHORITY_ERROR); 
//	}
//	
//	/**
//	 * 获取评论我的
//	 * @param count
//	 * @return
//	 */
//	@RequestMapping(value="/commentForMe",method=RequestMethod.GET)
//	@ApiOperation(value="获取评论我的")
//	public 	Map<String, Object>commentForMe(@ModelAttribute @Valid BaseCo co){
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) LocalUtil.get();
//		String userId =  userInfo.get("userId").toString();
//		return commentService.getCommentForMe(co,userId);
//		
//	}
//	/**
//	 * 获取我评论的
//	 * @param count
//	 * @return
//	 */
//	@RequestMapping(value="/myComment",method=RequestMethod.GET)
//	@ApiOperation(value="获取我评论的")
//	public 	Map<String, Object>myComment(@ModelAttribute @Valid BaseCo co){
//		@SuppressWarnings("unchecked")
//		Map<String,Object> userInfo  = (Map<String, Object>) LocalUtil.get();
//		String userId =  userInfo.get("userId").toString();
//		return commentService.getMyComment(co,userId);
//	}
//}
